import { DataSource } from "typeorm";
import { config } from 'dotenv';

import { Permission } from './user/entities/permission.entity';
import { Role } from './user/entities/role.entity';
import { User } from './user/entities/user.entity';
import { Blog } from "./blog/entities/blog.entity";
import { Upload } from "./upload/entities/upload.entity";
import { BlogCategory } from "./blog_category/entities/blog_category.entity";
import { BlogTag } from "./blog_tag/entities/blog_tag.entity";
import { Star } from "./star/entities/star.entity";
import { Like } from "./like/entities/like.entity";
import { Daily } from "./daily/entities/daily.entity";
import { Comment } from "./comment/entities/comment.entity";
import { Toutiao } from "./apis/entities/toutiao.entity";
import { History } from "./apis/entities/history.entity";
config({ path: 'src/.env-migration' });

console.log(process.env);

export default new DataSource({
    type: "mysql",
    host: `${process.env.mysql_server_host}`,
    port: +`${process.env.mysql_server_port}`,
    username: `${process.env.mysql_server_username}`,
    password: `${process.env.mysql_server_password}`,
    database: `${process.env.mysql_server_database}`,
    synchronize: false,
    logging: true,
    entities: [User, Role, Permission, Blog, Upload, BlogCategory, BlogTag, Star, Like, Comment, Daily, Toutiao, History],
    poolSize: 10,
    migrations: ['src/migrations/**.ts'],
    connectorPackage: 'mysql2',
    extra: {
        authPlugin: 'sha256_password',
    }
});
